<?php if (!defined("BASEPATH")) exit("No direct script access allowed");

class Tags extends MY_Controller {

	function __construct() {
		parent::__construct();
	}

	function _remap($tag) {
		$this->load->model("article_model");
		$urlName = "";
		$getArticle = $this->article_model->getArticle($where = "(cou_url_name = '".$this->db->escape_str($tag)."' or city_url_name = '".$this->db->escape_str($tag)."' or ins_url_name = '".$this->db->escape_str($tag)."' or maj_url_name = '".$this->db->escape_str($tag)."')");
		if(count($getArticle)) {
			$artIds = "";
			foreach($getArticle as $art) {
				$artIds .= (($artIds)?(", "):("")).$art["artId"];
			}
			$entList = preg_split("/,/", $art["entList"]);
			$entUrlList = preg_split("/,/", $art["entUrlList"]);
			foreach($entUrlList as $ii => $urlTitle) {
				if($urlTitle == $tag) {
					$urlName = trim($entList[$ii]);
				}
			}
			$params["getArticleList"] = $this->article_model->getArticle($where = "art_id in (".$artIds.")", $start = NULL, $limit = 10, $fields = NULL, $query = NULL, $order = "artCreatetime");
			$params["content"] = $this->load->view("page/article_list", $params, TRUE);
		} else {
			redirect("");
		}

		$params["getArticleKiemelt"] = $this->article_model->getArticle($where = "art_highlight = 'I'", $start = NULL, $limit = NULL, $fields = NULL, $query = NULL, $order = "artCreatetime");
		$params["activeTag"] = $tag;
		$params["breadcrumbs"] = array(
			"Tags",
			Common::coalesce(array($urlName, $tag)),
		);

		$params["getTags"] = $this->article_model->getTags();
		$params["sidebar"] = $this->load->view("page/sidebar", $params, TRUE);

		$this->load->view("template/page", $params);
	}

}